/*
 * Copyright (c) 2023 huipei.x
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.xphsc.kubernetes.boot.autoconfigure;

import cn.xphsc.kubernetes.core.KubernetesTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import cn.xphsc.kubernetes.boot.KubernetesProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * {@link }
 * @author <a href="xiongpeih@163.com">huipei.x</a>
 * @description:
 * @since 1.0.0
 */
@Configuration
@ConditionalOnProperty(
        prefix = KubernetesProperties.PREFIX,
        name = {"enabled"},
        havingValue = "true",
        matchIfMissing = true
)
@EnableConfigurationProperties({KubernetesProperties.class})
public class KubernetesAutoconfigure {
    private KubernetesProperties kubernttesProperties;

    public KubernetesAutoconfigure(KubernetesProperties kubernttesProperties){
        this.kubernttesProperties=kubernttesProperties;
    }

    @Bean
    public KubernetesTemplate kubernetesTemplate(){
        KubernetesTemplate template=new KubernetesTemplate();
        template.setKubeConfigPath(kubernttesProperties.getKubeConfigPath());
        template.setUsername(kubernttesProperties.getUsername());
        template.setPassword(kubernttesProperties.getPassword());
        template.setToken(kubernttesProperties.getToken());
        template.setUrl(kubernttesProperties.getUrl());
        template.setValidateSSL(kubernttesProperties.isValidateSSL());
        template.setConnectionTimeout(kubernttesProperties.getConnectionTimeout());
        template.setReadTimeout(kubernttesProperties.getReadTimeout());
        template.setWriteTimeout(kubernttesProperties.getWriteTimeout());
        return template;
    }


}






